Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0
,
where each “_” is a single digit.
In [ ]:
open System.Text.RegularExpressions
let upperBound = 1389244398I // sqrt(1930000000000000000I)
let lowerBound = 1000000000I
//let rawPattern = "1_2_3_4_5_6_7_8_9_0".Replace("_", ".").ToString()
let pattern = Regex("1.2.3.4.5.6.7.8.9.0")
let matches n =
let m = pattern.Match (string(n))
m.Success
seq { lowerBound .. upperBound }
|> Seq.filter (fun n -> matches (n * n))
|> Seq.first
In [ ]: